package javaDemo02;

import java.util.ArrayList;
import java.util.Scanner;

public class Shopping {//选购类

    public Shopping() {
    }

    public static void one1_1(ArrayList<Commodity> arr,ArrayList<Shopping_Car> car) {
        System.out.println("请输入您要购买的商品项(格式为:商品id-购买数量),输入end表示购买结束");
        while (true){
            Scanner sc = new Scanner(System.in);
            String input = sc.nextLine();
            String[] temp = input.split("-");

            if (temp.length == 1 && temp[0].equals("end")) {
                System.out.println("购买结束");
                System.out.println("-------------------------------------");
                break;
            }

            boolean found = false;
            if (temp.length == 2) {
                for (Commodity commodity : arr) {
                    String mb = commodity.getId();
                    if (mb.equals(temp[0])) {
                        Shopping_Car md = new Shopping_Car();
                        md.setName(commodity.getName());
                        md.setPrice(commodity.getPrice());
                        md.setNumber(Integer.valueOf(temp[1]));
                        car.add(md);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    System.out.println("您输入的商品id不存在，请重新输入");
                }
            }else if (temp.length != 2){
                System.out.println("你输入的购买格式不对，请重新输入(格式为:商品id-购买数量)");
            }


        }
    }
}
